package com.haircut.api.salary;

import cn.hutool.core.date.DateUtil;
import com.haircut.project.service.salary.ISalaryService;
import com.haircut.project.vo.salary.ApiSalaryConfirmVo;
import com.haircut.project.vo.salary.ApiSalaryReqVo;
import com.haircut.project.vo.salary.ApiSalaryResVo;
import com.haircut.sys.utils.user.SecurityUtils;
import com.modular.result.PageResult;
import com.modular.result.RspMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(tags = "工资管理")
@RestController
@RequestMapping("/api/salary")
public class ApiSalaryController {
    @Autowired
    private ISalaryService salaryService;
    /**
     * 分页查询我的记录信息
     * @return
     */
    @ApiOperation(value = "查询我的记录信息")
    @PostMapping("/findPage")
    public RspMessage<PageResult<ApiSalaryResVo>> findPage(@Validated @RequestBody ApiSalaryReqVo reqVo){
        reqVo.setUserId(SecurityUtils.getUserId());
        Date currDate = DateUtil.date();
        reqVo.setStatTime(DateUtil.beginOfDay(DateUtil.offsetMonth(currDate,-12)));
        reqVo.setEndTime(DateUtil.endOfDay(currDate));
        return RspMessage.success(salaryService.findApiPage(reqVo));
    }

    /**
     * 分页查询我的记录信息
     * @return
     */
    @ApiOperation(value = "确认工资")
    @PostMapping("/confirmSalary")
    public RspMessage<Void> confirmSalary(@Validated @RequestBody ApiSalaryConfirmVo reqVo){
        salaryService.confirmSalary(reqVo);
        return RspMessage.success();
    }

}
